// ValidationAspects
// Written by Mike Saunders
// Released under Microsoft Public License (Ms-PL)
using NUnit.Framework;
using ValidationAspects.Exceptions;
using ValidationAspects.Factories;
using ValidationAspects.Sdk;

namespace TestValidationAspects.Factories
{
	[TestFixture]
	public class TestMatchesRegex
	{
		[Test]
		public void Test_MatchesRegex()
		{
			IValidator<string> validator = new MatchesRegex {Regex = "1", Name = "name"}.Create<string>();

			validator.Invoke("123", new MockValidationContext());

			try
			{
				validator.Invoke("234", new MockValidationContext());
			}
			catch (ValidateMatchesRegexException e)
			{
				Assert.AreEqual("name", e.Name);
				return;
			}
			Assert.Fail("ValidateMatchesRegexException not thrown.");
		}

		[Test]
		public void Test_validation_skips_null_value()
		{
			IValidator<string> validator = new MatchesRegex {Regex = "1", Name = "name"}.Create<string>();
			validator.Invoke(null, new MockValidationContext());
		}
	}
}